package ad.android.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class FileReaderUtil {

	public static String readTmplHtml(String tmplName) throws IOException {
		InputStream is = null;
		try {
			String html = "";
//			is = FileReaderUtil.class.getResourceAsStream(Constants.tmplBaseUrl+ tmplName);
//			is = FileReaderUtil.class.getResourceAsStream("/src/ad/android/res/tmpl/tmpl110914.html");
			ClassLoader loader = Thread.currentThread().getContextClassLoader(); 
			URL url = loader.getResource(Constants.tmplBaseUrl+tmplName); 
			File file = new File( url.getFile() );
//			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader( new FileReader(file));
			String line = null;
			while ((line = br.readLine()) != null) {
				html += line;
			}

			return html;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		} finally {
			if (is != null) {
				is.close();
			}
		}
	}
}
